<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./js/react.min.js"></script>
    <script src="./js/react-dom.min.js"></script>
    <script src="./js/babel.js"> </script>
</head>
<body>
    <div id="example"></div>
    <script type="text/babel">
        class App extends React.Component {
            constructor(props) {
                super(props)
                this.state = {
                    name: 'zhangsan'
                }
                this.handleChange = this.handleChange.bind(this)
            }
            handleChange() {
                this.setState({
                    name: 'lisi' // 触发页面更新事件
                })
            }
            handleRemove() {
                ReactDOM.unmountComponentAtNode(document.getElementById('example'))
            }

            componentWillMount() {
                console.log('页面将要被渲染')
            }
            componentDidMount() {
                console.log('页面渲染完成')
            }
            componentWillUpdate() {
                console.log('页面将要更新')
            }
            componentDidUpdate() {
                console.log('页面更新完成')
            }
            componentWillUnmount() {
                console.log('页面组件将要被移除')
            }
            render() {
                return (
                    <div>
                        <h3>虚拟DOM渲染了</h3>
                        <input type="text" onChange={this.handleChange}/>
                        <button onClick={this.handleRemove}>点击移除</button>
                    </div>
                )
            }
        }
        ReactDOM.render(<App />, document.getElementById('example'))
    </script>
</body>
</html>